﻿using System;
using System.Web.Configuration;

namespace Salient.Web.Administration.Security.Wizard
{
    public partial class wizardAuthentication : WebAdminUserControl
    {
        public void Page_Load()
        {
            if (!IsPostBack)
            {
                System.Configuration.Configuration config =
                    ((WebAdminPage) Page).OpenWebConfiguration((string) Session["WebAdminApplicationPath"]);
                var auth = (AuthenticationSection) config.GetSection("system.web/authentication");
                fromInternet.Checked = auth.Mode == AuthenticationMode.Forms;
                fromNetwork.Checked = auth.Mode == AuthenticationMode.Windows;
            }
        }

        public void UpdateAuth(object sender, EventArgs e)
        {
            System.Configuration.Configuration config =
                ((WebAdminPage) Page).OpenWebConfiguration((string) Session["WebAdminApplicationPath"]);
            var auth = (AuthenticationSection) config.GetSection("system.web/authentication");
            auth.Mode = fromInternet.Checked ? AuthenticationMode.Forms : AuthenticationMode.Windows;
            ((WebAdminPage) Page).SaveConfig(config);
        }

        public override bool OnNext()
        {
            UpdateAuth(null, null);
            return true;
        }
    }
}